<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="${ctx}/css_inc"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>触点分类管理</title>

</head>

<body class="">
	<div class="row">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<form class="form-horizontal m-t" id="catagoryForm">
					<div class="form-group">
						<label class="col-sm-3 control-label">触点分类：</label>
						<div class="col-sm-8">
							<input id="catagoryName" name="catagoryName" class="form-control" type="text"  value="${pointCatagory.catagoryName}">
							<input id="catagoryId" name="catagoryId" type="hidden" value="${pointCatagory.catagoryId}" />
						</div>
					</div>
					<div class="form-group" style="display:none">
						<label class="col-sm-3 control-label">层级：</label>
						<div class="col-sm-8">
							<input id="catagoryLevel" name="catagoryLevel" class="form-control" type="text"  value="${pointCatagory.catagoryLevel}">	 
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">上级分类：</label>
						<div class="col-sm-8">
							<input id="parentId" name="parentId" class=" form-control tree-select" data-value="${pointCatagory.parentId}" value="${pointCatagory.parentName}">
 						</div>
					</div>
					
					<div class="form-group">
						<label class="col-sm-3 control-label">排序：</label>
						<div class="col-sm-8">
							<input id="sortBy" name="sortBy" class="form-control" type="number" value="${pointCatagory.sortBy}" >
						</div>
					</div> 
				</form>
			</div>
		</div>
	</div>
	<jsp:include page="${ctx}/js_inc"></jsp:include>
	<script type="text/javascript">
	$.validator.addMethod("checkCatagoryParentId", function(value, element) {   
	    var catagoryId = $('#catagoryId').val();
	    var pCatagoryId = $('#parentId').data('value');
	    if(catagoryId !='' && catagoryId==pCatagoryId){
	    	return false;
	    }
	    return true 
	    	
	}, '不能选择自身作为上级分类');
 	var catagroyNodes;
	$().ready(function() {
		$('#catagoryForm').validate({
			rules : {
				catagoryName : 'required', 
				parentId : 'checkCatagoryParentId'
			},
			messages : {
				catagoryName : validatorIcon + '请输入分类' 
			},
			onfocusout: function(element){$(element).valid();}
		});
		initCatagroyNodes(); 
		$('#parentId').click(function(){
			treeSelect(this,catagroyNodes,true);
			return false;
		});
	});
 
 	
 	function initCatagroyNodes(){
 		$.post('${ctx}/contactmgn/point/getPointCatagoryTree', 
    			function (data) {if(data.success){
    				catagroyNodes = data.obj;  
    			}}
    	); 
 	} 
 	
	function parentIdonClick(e, treeId, treeNode) {
  		var obj = $('#parentId');
		obj.attr('value', treeNode.name);
		obj.data('value',treeNode.id); 
		var level = treeNode.level+1; 
		$('#catagoryLevel').val(level); 
		obj.focusout();
	}




	
	</script> 
</body>

</html>
